package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArDonateSource;
import net.sk.china.city.service.IArDonateSourceService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 捐赠来源Controller
 * 
 * @author gxf
 * @date 2024-04-24
 */
@Api(tags = "捐赠来源")
@RequiredArgsConstructor
@RestController
@RequestMapping("/donate/source")
public class ArDonateSourceController extends BaseController
{
    @Autowired
    private IArDonateSourceService arDonateSourceService;

    /**
     * 查询捐赠来源列表
     */
    @ApiOperation("捐赠来源列表")
    @PreAuthorize("hasAnyAuthority('donate:source:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArDonateSource arDonateSource)
    {
        startPage();
        List<ArDonateSource> list = arDonateSourceService.selectArDonateSourceList(arDonateSource);
        return getDataTable(list);
    }

    /**
     * 导出捐赠来源列表
     */
    @PreAuthorize("hasAnyAuthority('donate:source:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArDonateSource arDonateSource)
    {
        List<ArDonateSource> list = arDonateSourceService.selectArDonateSourceList(arDonateSource);
//        ExcelUtil<ArDonateSource> util = new ExcelUtil<ArDonateSource>(ArDonateSource.class);
//        util.exportExcel(response, list, "捐赠来源数据");
    }

    /**
     * 获取捐赠来源详细信息
     */
    @ApiOperation("捐赠来源详情")
    @PreAuthorize("hasAnyAuthority('donate:source:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arDonateSourceService.selectArDonateSourceById(id));
    }

    /**
     * 新增捐赠来源
     */
    @ApiOperation("新增捐赠来源")
    @PreAuthorize("hasAnyAuthority('donate:source:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArDonateSource arDonateSource)
    {
        return toAjax(arDonateSourceService.insertArDonateSource(arDonateSource));
    }

    /**
     * 修改捐赠来源
     */
    @ApiOperation("修改捐赠来源")
    @PreAuthorize("hasAnyAuthority('donate:source:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArDonateSource arDonateSource)
    {
        return toAjax(arDonateSourceService.updateArDonateSource(arDonateSource));
    }

    /**
     * 删除捐赠来源
     */
    @ApiOperation("删除捐赠来源")
    @PreAuthorize("hasAnyAuthority('donate:source:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        //todo 逻辑删除
        return toAjax(arDonateSourceService.deleteArDonateSourceByIds(ids));
    }


    @ApiOperation("所有捐赠来源")
    @GetMapping("/donateList")
    public AjaxResult donateList()
    {
        return success(arDonateSourceService.donateList());
    }
}
